

#libraries and modules
import numpy as np
import matplotlib.pyplot as plt




def f_Tt_ShF(n,L,P2,s):
    #INPUT:
    #n          Manning's roughness coefficient (TR55 table3-1)
    #L          flow length (ft)
    #P2         24-hour rainfall with 2-year return period (in)
    #s          slope of hydraulic gradeline / land slope (ft/ft)

    #DESCRIPTION:
    #compute time of travel of sheet flow; valid for flow lengths <=300 ft

    #OUTPUT:
    #Tt_ShF   travel time in hours 

    Tt_ShF=(0.007*(n*L)**0.8) / ((P2**0.5)*(s**0.4))    #TR55 eq 3-3
    
    return Tt_ShF


def f_Tt_SCF(s, pc_paved,L_SCF):
    #INPUT:
    #s          slope of hydraulic gradeline / land slope (ft/ft)
    #pc_paved   value from 0 to 1; 0 unpaved, 1 paved
    #L_SCF      length of shallow concentrated flow in feet

    #DESCRIPTION:
    #compute time of travel of shallow concentrated flow

    #OUTPUT:
    #Tt_SCF     travel time in hours

    Vu=16.1345*s**0.5    #velocity for unpaved
    Vp=20.3282*s**0.5    #velocity for paved
    V=Vu+pc_paved*(Vp-Vu)   #velocity for actual condition (ft/sec)

    Tt_SCF=(L_SCF/V)/3600.   #travel time in hours

    return Tt_SCF


def f_Tt_ChF(a,pw,s,n,L_ChF):
    #INPUT:
    #a              cross-sectional flow area, ft^2              precipitation, in inches
    #pw             wetted perimeter, ft
    #s          slope of hydraulic gradeline / channel slope (ft/ft)
    #n          Manning's roughness coefficient (TR55 table3-1)
    #L_ChF      length of channelized flow in feet

             

    #DESCRIPTION:
    #compute time of travel of channelized flow

    #OUTPUT:
    #Tt_ChF     travel time in hours

    V=(1.49*(a/pw)**(2/3.)*s**0.5)/n   #ft/sec

    Tt_ChF=(L_ChF/V)/3600.  #travel time in hours

    return Tt_ChF


def trial_compute_TR55():
    #Example 3-1
    Tt_ShF=f_Tt_ShF(.24,100,3.6,0.01)
    Tt_SCF=f_Tt_SCF(0.01, 0,1400)
    Tt_ChF=f_Tt_ChF(27,28.2,.005,0.05,7300)
    T=Tt_ShF+Tt_SCF+Tt_ChF
    print Tt_ShF,Tt_SCF,Tt_ChF,T

#trial_compute_TR55()


